package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.iotModule.WisdomElectricityAlarmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2021/12/17
 * @Description
 */
@Api(tags = "智慧用电告警接口")
@RestController
@RequestMapping("WisdomElectricity")
@CrossOrigin
public class WisdomElectricityAlarmController {
    @Autowired
    private WisdomElectricityAlarmsService wisdomElectricityAlarmsService;

    @ApiOperation(value = "查询所有告警信息", notes = "")
    @PostMapping("/findWisdomElectricityAlarmsByAll")
    public OneDataResult findWisdomElectricityAlarmsByAll(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(wisdomElectricityAlarmsService.findWisdomElectricityAlarmsByAll(map));
        return oneDataResult;
    }

    @ApiOperation(value = "预警分布", notes = "")
    @PostMapping("/countWisdomElectricityAlarmsByAlarmStatus")
    public OneDataResult countWisdomElectricityAlarmsByAlarmStatus(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(wisdomElectricityAlarmsService.countWisdomElectricityAlarmsByAlarmStatus(map));
        return oneDataResult;
    }

    @ApiOperation(value = "删除智慧用电告警记录", notes = "测试数据:")
    @PostMapping("/deleteWisdomElectricityAlarms")
    public JsonResult deleteWisdomElectricityAlarms(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = wisdomElectricityAlarmsService.deleteWisdomElectricityAlarms(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除智慧用电告警信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除智慧用电告警信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页查询智慧用电告警记录", notes = "测试数据:")
    @PostMapping("/findWisdomElectricityAlarmsByPage")
    public Page findWisdomElectricityAlarmsByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(wisdomElectricityAlarmsService.Total(map));
        page.setItems(wisdomElectricityAlarmsService.findWisdomElectricityAlarmsByPage(map));
        return page;
    }
}
